home *** CD-ROM | disk | FTP | other *** search
- #ifdef __TURBOC__
- #include <sys\types.h>
- #else
- #include <sys/types.h>
- #endif
- #include <unistd.h>
- #include <osbind.h>
- #include <mintbind.h>
- #include <errno.h>
- #include <ioctl.h>
- #include <fcntl.h>
- #include "lib.h"
-
- extern int __mint;
-
- pid_t
- getpgrp()
- {
- return __mint ? Pgetpgrp() : 0;
- }
-
- int
- _bsd_setpgrp(pid, grp)
- int pid, grp;
- {
- int r = 0;
-
- if (__mint) {
- r = Psetpgrp(pid, grp);
- if (r < 0) {
- errno = -r;
- r = -1;
- }
- }
- return r;
- }
-
- int
- setpgrp()
- {
- return __mint ? Psetpgrp(0, 0) : 0;
- }
-
- int
- _bsd_getpgrp(pid)
- int pid;
- {
- if (__mint >= 0x103) return _bsd_setpgrp(pid, -1);
- return 0;
- }
-
- int
- setpgid(pid, pgid)
- pid_t pid, pgid;
- {
- int r = 0;
-
- if (__mint) {
- r = Psetpgrp((int) pid, (int) pgid);
- if (r < 0) {
- errno = -r;
- r = -1;
- }
- }
- return r;
- }
-
- pid_t
- setsid()
- {
- long tty_pgrp;
- long prc_pgrp;
- int tty_fd;
- int rc;
-
- if (!__mint) {
- errno = EINVAL;
- return (pid_t) -1;
- }
- prc_pgrp = Pgetpgrp();
- if (prc_pgrp != Pgetpid()) {
- if (isatty(-1)) {
- tty_fd = open("/dev/tty", O_RDWR | O_NOCTTY);
- if (tty_fd < __SMALLEST_VALID_HANDLE) {
- return (pid_t) -1;
- }
- rc = (int) Fcntl(-1, &tty_pgrp, TIOCGPGRP);
- if (rc < 0) {
- errno = -rc;
- return (pid_t) -1;
- }
- if (tty_pgrp == prc_pgrp) {
- tty_pgrp = 0;
- rc = (int) Fcntl(-1, &tty_pgrp, TIOCSPGRP);
- if (rc < 0) {
- errno = -rc;
- return (pid_t) -1;
- }
- }
- if (ioctl(tty_fd, TIOCNOTTY, 0) < 0) return -1;
- (void) close(tty_fd);
- }
- }
- rc = (int) Psetpgrp(0, 0);
- if (rc < 0) {
- errno = -rc;
- rc = -1;
- }
- return (pid_t) rc;
- }
-